package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.common.constant.ClueStatusConstants;
import com.qk.dpmain.clue.ClueDo;
import com.qk.dto.clue.ClueDto;
import com.qk.dto.clue.ClueFakeDto;
import com.qk.dto.clue.ClueListDto;
import com.qk.dto.clue.UpdateClueInfoDTO;
import com.qk.entity.Clue;
import com.qk.management.aop.anno.LogAnno;
import com.qk.management.service.ClueService;
import com.qk.vo.clue.ClueVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * @文件名: ClueController
 * @作者: DX
 * @创建日期: 2025/10/13
 * @描述:
 */
@Slf4j
@RestController
@RequestMapping("/clues")
public class ClueController {

    @Autowired
    private ClueService clueService;

    @GetMapping("/pool")
    public Result cluePoolList(ClueListDto dto){
        log.info("查询线索池列表：{}", dto);
        PageResult<Clue> pageResult = clueService.cluePollList(dto);
        return Result.success(pageResult);
    }

    @LogAnno
    @PutMapping("/false/{id}")
    public Result toFake(@PathVariable Integer id , @RequestBody ClueFakeDto dto){
        clueService.toFake(id , dto);
        return Result.success();
    }

    @LogAnno
    @PutMapping("toBusiness/{id}")
    public  Result toBusiness(@PathVariable Integer id){
        clueService.toBusiness(id);
        return Result.success();
    }

    @LogAnno
    @PutMapping
    public Result updateClueInfoById(@RequestBody UpdateClueInfoDTO dto) {
        clueService.updateClueInfoById(dto);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getClueInfoById(@PathVariable Integer id){
        ClueVo vo= clueService.getClueInfoById(id);
        return Result.success(vo);
    }


    @LogAnno
    @PutMapping("/assign/{clueId}/{userId}")
    public Result updateClueById(@PathVariable Integer clueId, @PathVariable Integer userId) {
        clueService.updateById(ClueDo.builder()
                .id(clueId)
                .userId(userId)
                .updateTime(LocalDateTime.now())
                .status(ClueStatusConstants.WAIT_FOLLOW_UP)
                .build());
        return Result.success();
    }

    @GetMapping
    public Result list(ClueListDto dto) {
        PageResult<ClueDo> pageResult = clueService.clueList(dto);
        return Result.success(pageResult);
    }

    @LogAnno
    @PostMapping
    public Result addClue(@RequestBody ClueDto dto) {

        clueService.addCule(dto);

        return Result.success();
    }
}
